package com.x.gzcrm.service.impl;


import com.x.gzcrm.mapper.CourseOrderMapper;
import com.x.gzcrm.model.CourseOrder;
import com.x.gzcrm.model.MonthIncome;
import com.x.gzcrm.model.PageResult;
import com.x.gzcrm.service.ICourseOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class CourseOrderServiceImpl implements ICourseOrderService{
    @Autowired
    CourseOrderMapper courseOrderMapper;


    @Override
    public PageResult<CourseOrder> findPageResult(CourseOrder condition, int page, int pageSize) {
        PageResult<CourseOrder> result=new PageResult<>();
        result.setCode(0);

        /*
         查询参数先设置为空
         */
        Map<String ,Object> params =new HashMap<String, Object>();
        params.put("condition",condition);//模糊查询条件
        // select * from XXX limit 0,10
        params.put("start",(page-1)*pageSize);
        params.put("pageSize",pageSize);

        //获取总记录数据
        int totalCount = courseOrderMapper.findCountByMap(params);
        result.setCount(totalCount);
        //获取查询的数据
        List<CourseOrder> list = courseOrderMapper.findListByMap(params);
        result.setData(list);
        return result;
    }

    @Override
    public void save(CourseOrder order) {
        courseOrderMapper.insert(order);
    }

    @Override
    public CourseOrder findByOrderId(String order_id) {
        return courseOrderMapper.findByOrderId(order_id);
    }

    @Override
    public void deleteByOrderId(String order_id) {
        courseOrderMapper.deleteByOrderId(order_id);
    }

    @Override
    public void update(CourseOrder order) {
        courseOrderMapper.update(order);
    }

    @Override
    public List<MonthIncome> getMonthIncomes() {
        return courseOrderMapper.getMonthIncomes();
    }


}
